/*
 * Copyright 2001:
 * Peter Andersson <petan117@student.liu.se>
 * Martin Hagman <marha189@student.liu.se>
 * Henrik Norin <henno776@student.liu.se>
 * Anna Stjerneby <annst566@student.liu.se>
 * Tim Terleg�rd <timte878@student.liu.se>
 * Johan Trygg <johtr599@student.liu.se>
 * Peter �strand <petas096@student.liu.se>
 *
 * This file is part of reMIND.
 *
 * reMIND is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * reMIND is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with reMIND; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

/*
 * NewResourceDialog.java
 *
 * Created on den 5 maj 2001, 17:32
 */

/**
 *
 * @author Tim Terleg�rd
 * @version 2001-05-01
 */

package mind.gui.dialog;

import mind.gui.*;
import mind.model.*;

public class NewResourceDialog extends javax.swing.JDialog {
    GUI c_gui;

    /** Creates new form NewResourceDialog */
    public NewResourceDialog(javax.swing.JDialog parent, boolean modal,
			     GUI gui) {
	super (parent, modal);
	c_gui = gui;
	initComponents ();
	pack ();
    }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the FormEditor.
   */
  private void initComponents () {
    pnlName = new javax.swing.JPanel ();
    lblName = new javax.swing.JLabel ();
    txtName = new javax.swing.JTextField ();
    pnlUnit = new javax.swing.JPanel ();
    lblUnit = new javax.swing.JLabel ();
    txtUnit = new javax.swing.JTextField ();
//    pnlPrefix = new javax.swing.JPanel ();
//    lblPrefix = new javax.swing.JLabel ();
//    txtPrefix = new javax.swing.JTextField ();
    pnlColor = new javax.swing.JPanel();
    lblColor = new javax.swing.JLabel();
    comboBoxColor = new ColorComboBox();
    pnlButtons = new javax.swing.JPanel ();
    btnOK = new javax.swing.JButton ();
    btnCancel = new javax.swing.JButton ();
    sepNewResource = new javax.swing.JSeparator ();
    getContentPane ().setLayout (new java.awt.GridBagLayout ());
    java.awt.GridBagConstraints gridBagConstraints1;
    addWindowListener (new java.awt.event.WindowAdapter () {
      public void windowClosing (java.awt.event.WindowEvent evt) {
        closeDialog (evt);
      }
    }
    );

    pnlName.setLayout (new java.awt.GridBagLayout ());
    java.awt.GridBagConstraints gridBagConstraints2;

      lblName.setText ("Name:");

      gridBagConstraints2 = new java.awt.GridBagConstraints ();
      gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
      pnlName.add (lblName, gridBagConstraints2);


      gridBagConstraints2 = new java.awt.GridBagConstraints ();
      gridBagConstraints2.gridx = 0;
      gridBagConstraints2.gridy = 1;
      gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
      gridBagConstraints2.insets = new java.awt.Insets (3, 0, 0, 0);
      gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
      gridBagConstraints2.weightx = 1.0;
      pnlName.add (txtName, gridBagConstraints2);


    gridBagConstraints1 = new java.awt.GridBagConstraints ();
    gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints1.insets = new java.awt.Insets (10, 10, 10, 10);
    gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints1.weightx = 1.0;
    getContentPane ().add (pnlName, gridBagConstraints1);

    pnlUnit.setLayout (new java.awt.GridBagLayout ());
    java.awt.GridBagConstraints gridBagConstraints3;

      lblUnit.setText ("Unit:");

      gridBagConstraints3 = new java.awt.GridBagConstraints ();
      gridBagConstraints3.anchor = java.awt.GridBagConstraints.WEST;
      pnlUnit.add (lblUnit, gridBagConstraints3);


      gridBagConstraints3 = new java.awt.GridBagConstraints ();
      gridBagConstraints3.gridx = 0;
      gridBagConstraints3.gridy = 1;
      gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
      gridBagConstraints3.insets = new java.awt.Insets (3, 0, 0, 0);
      gridBagConstraints3.weightx = 1.0;
      pnlUnit.add (txtUnit, gridBagConstraints3);


    gridBagConstraints1 = new java.awt.GridBagConstraints ();
    gridBagConstraints1.gridx = 0;
    gridBagConstraints1.gridy = 1;
    gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints1.insets = new java.awt.Insets (10, 10, 10, 10);
    gridBagConstraints1.weightx = 1.0;
    getContentPane ().add (pnlUnit, gridBagConstraints1);

     java.awt.GridBagConstraints gridBagConstraints4;
/*    pnlPrefix.setLayout (new java.awt.GridBagLayout ());
   

      lblPrefix.setText ("Prefix:");

      gridBagConstraints4 = new java.awt.GridBagConstraints ();
      gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST;
      gridBagConstraints4.weightx = 1.0;
      pnlPrefix.add (lblPrefix, gridBagConstraints4);

      txtPrefix.setColumns (7);

      gridBagConstraints4 = new java.awt.GridBagConstraints ();
      gridBagConstraints4.gridx = 0;
      gridBagConstraints4.gridy = 1;
      gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST;
      gridBagConstraints4.weightx = 1.0;
      pnlPrefix.add (txtPrefix, gridBagConstraints4);

    gridBagConstraints1 = new java.awt.GridBagConstraints ();
    gridBagConstraints1.gridx = 0;
    gridBagConstraints1.gridy = 2;
    gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints1.insets = new java.awt.Insets (10, 10, 10, 10);
    gridBagConstraints1.weightx = 1.0;
    getContentPane ().add (pnlPrefix, gridBagConstraints1);*/

    //Setting label
    lblColor.setText("Color:");
    pnlColor.setLayout(new java.awt.GridBagLayout());

    //Ading the combopanel to our dialog
    gridBagConstraints1 = new java.awt.GridBagConstraints ();
    gridBagConstraints1.gridx = 0;
    gridBagConstraints1.gridy = 3;
    gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints1.insets = new java.awt.Insets (10, 10, 30, 10);
    gridBagConstraints1.weightx = 1.0;

    gridBagConstraints4 = new java.awt.GridBagConstraints ();
    gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints4.weightx = 1.0;
    pnlColor.add(lblColor, gridBagConstraints4);

    gridBagConstraints4 = new java.awt.GridBagConstraints ();
    gridBagConstraints4.gridx = 0;
    gridBagConstraints4.gridy = 1;
    gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST;
    gridBagConstraints4.weightx = 1.0;

    pnlColor.add(comboBoxColor, gridBagConstraints4);
    getContentPane().add(pnlColor, gridBagConstraints1);

    //Adding buttons

      btnOK.setText ("OK");
      getRootPane().setDefaultButton(btnOK);
      btnOK.addActionListener (new java.awt.event.ActionListener () {
        public void actionPerformed (java.awt.event.ActionEvent evt) {
          btnOKActionPerformed (evt);
        }
      }
      );

      pnlButtons.add (btnOK);

      btnCancel.setText ("Cancel");
      btnCancel.addActionListener (new java.awt.event.ActionListener () {
        public void actionPerformed (java.awt.event.ActionEvent evt) {
          btnCancelActionPerformed (evt);
        }
      }
      );

      pnlButtons.add (btnCancel);


    gridBagConstraints1 = new java.awt.GridBagConstraints ();
    gridBagConstraints1.gridx = 0;
    gridBagConstraints1.gridy = 5;
    gridBagConstraints1.insets = new java.awt.Insets (10, 10, 10, 10);
    gridBagConstraints1.anchor = java.awt.GridBagConstraints.EAST;
    gridBagConstraints1.weightx = 1.0;
    getContentPane ().add (pnlButtons, gridBagConstraints1);

    sepNewResource.setPreferredSize (new java.awt.Dimension(10, 2));


    gridBagConstraints1 = new java.awt.GridBagConstraints ();
    gridBagConstraints1.gridx = 0;
    gridBagConstraints1.gridy = 4;
    gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints1.weightx = 1.0;
    getContentPane ().add (sepNewResource, gridBagConstraints1);

  }

  private void btnCancelActionPerformed (java.awt.event.ActionEvent evt) {
    closeDialog(null);
  }

  private void btnOKActionPerformed (java.awt.event.ActionEvent evt) {
      c_gui.addResource(txtName.getText(), txtUnit.getText(),"", (ExtendedColor)comboBoxColor.getSelectedItem());
      closeDialog(null);
  }

    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {
	setVisible (false);
	dispose ();
    }

    public static void main(String[] args)
    {
	new NewResourceDialog(new javax.swing.JDialog(), true, (GUI)null).show();
    }


    private javax.swing.JPanel pnlName;
    private javax.swing.JLabel lblName;
    private javax.swing.JTextField txtName;
    private javax.swing.JPanel pnlUnit;
    private javax.swing.JLabel lblUnit;
    private javax.swing.JTextField txtUnit;
  //  private javax.swing.JPanel pnlPrefix;
  //  private javax.swing.JLabel lblPrefix;
   // private javax.swing.JTextField txtPrefix;
    private javax.swing.JPanel pnlColor;
    private javax.swing.JLabel lblColor;
    private ColorComboBox comboBoxColor;
    private javax.swing.JPanel pnlButtons;
    private javax.swing.JButton btnOK;
    private javax.swing.JButton btnCancel;
    private javax.swing.JSeparator sepNewResource;
}
